package com.wanda.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.wanda.model.Wd_RoleModel;
import com.wanda.util.PaymentUtil;

@RequestMapping(value="/pay")
@Controller
public class ZhiFuController {
	
	//银行卡支付
	@RequestMapping(value="/kapay")
    public ModelAndView add(HttpServletRequest request, HttpServletResponse response){
		//alert("href=pay/kapay?zfyh="+c+"&ddh="+ddh+"&sj="+sj);
		
		String xm = "http://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();
		
		System.err.println("zou le");
		String orderid = request.getParameter("ddh");   
		String money = request.getParameter("sj");
		String pd_Id = request.getParameter("zfyh");
		System.err.println("zou le"+orderid+money+pd_Id);
		String p0_Cmd = "Buy";
		String p1_MerId = "10001126856";// 真实
		String p2_Order = orderid;
		String p3_Amt = money;
		String p4_Cur = "CNY";
		String p5_Pid = "";
		String p6_Pcat = "";
		String p7_Pdesc = "";
		String p8_Url = xm+"/qt/kapay2.jsp";
		String p9_SAF = "";
		String pa_MP = "";
		String pd_FrpId = pd_Id;
		String pr_NeedResponse = "";

		String keyValue = "69cl522AV6q613Ii4W6u8K6XuW8vM1N6bFgyv769220IuYe9u37N4y7rI4Pl";

		String hmac = PaymentUtil.buildHmac(p0_Cmd, p1_MerId, p2_Order, p3_Amt, p4_Cur,
				p5_Pid, p6_Pcat, p7_Pdesc, p8_Url, p9_SAF, pa_MP, pd_FrpId,
				pr_NeedResponse, keyValue);
		
		// 将所有参数 发送给 易宝指定URL
		request.setAttribute("pd_FrpId", pd_FrpId);
		request.setAttribute("p0_Cmd", p0_Cmd);   
		request.setAttribute("p1_MerId", p1_MerId);
		request.setAttribute("p2_Order", p2_Order);
		request.setAttribute("p3_Amt", p3_Amt);
		request.setAttribute("p4_Cur", p4_Cur);
		request.setAttribute("p5_Pid", p5_Pid);
		request.setAttribute("p6_Pcat", p6_Pcat);
		request.setAttribute("p7_Pdesc", p7_Pdesc);
		request.setAttribute("p8_Url", p8_Url);
		request.setAttribute("p9_SAF", p9_SAF);
		request.setAttribute("pa_MP", pa_MP);
		request.setAttribute("pr_NeedResponse", pr_NeedResponse);
		request.setAttribute("hmac", hmac);
		ModelAndView MAV = new ModelAndView("../qt/kapay1.jsp");
		return MAV;
    }
}
